#!/usr/bin/env python3
"""
Example usage of the Roboflow Dataset Downloader

This script demonstrates how to use the RoboflowDownloader class
to download datasets programmatically.
"""

from download_dataset import RoboflowDownloader
import os

def example_usage():
    """Example of how to use the RoboflowDownloader"""
    
    # Check if API key is set
    if not os.getenv('ROBOFLOW_API_KEY'):
        print("Please set your ROBOFLOW_API_KEY in the .env file first!")
        print("1. Copy .env.example to .env")
        print("2. Edit .env and add your API key from https://roboflow.com/")
        return
    
    try:
        # Initialize the downloader
        print("Initializing Roboflow downloader...")
        downloader = RoboflowDownloader()
        
        # Example 1: Show workspace listing info
        print("\n=== Example 1: Workspace Information ===")
        downloader.list_workspaces()
        
        # Example 2: Show project listing info for a sample workspace
        print("\n=== Example 2: Project Listing Information ===")
        print("For demonstration, let's try with a sample workspace name:")
        downloader.list_projects("your-workspace-name")
        
        # Example 3: Show how to get dataset info (requires real workspace/project names)
        print("\n=== Example 3: Dataset Information ===")
        print("To get dataset information, you need real workspace and project names:")
        print("Example: dataset_info = downloader.get_dataset_info('workspace-name', 'project-name')")
        
        # Example 4: Show download command examples
        print("\n=== Example 4: Download Examples ===")
        print("To download datasets, use these command line examples:")
        print("python download_dataset.py --workspace YOUR_WORKSPACE --project YOUR_PROJECT")
        print("python download_dataset.py --workspace YOUR_WORKSPACE --project YOUR_PROJECT --version 2 --format coco")
        print("python download_dataset.py --workspace YOUR_WORKSPACE --project YOUR_PROJECT --output ./my_datasets")
        
        # Example 5: Programmatic download (commented out)
        print("\n=== Example 5: Programmatic Download (Template) ===")
        print("To download programmatically, uncomment and modify these lines:")
        print("# success = downloader.download_dataset(")
        print("#     workspace_name='your-workspace-name',")
        print("#     project_name='your-project-name',")
        print("#     version=1,")
        print("#     format_type='yolov8',")
        print("#     download_dir='./datasets'")
        print("# )")
        
        # Real example with placeholder values (commented out to avoid errors)
        # Replace 'your-workspace-name' and 'your-project-name' with actual values
        # print("\n=== Downloading Dataset ===")
        # success = downloader.download_dataset(
        #     workspace_name='your-workspace-name',
        #     project_name='your-project-name',
        #     version=1,
        #     format_type='yolov8',
        #     download_dir='./datasets'
        # )
        # 
        # if success:
        #     print("Dataset downloaded successfully!")
        # else:
        #     print("Failed to download dataset.")
        
        print("\n=== Example Complete ===")
        print("To download real datasets:")
        print("1. Find your workspace and project names in the Roboflow dashboard")
        print("2. Use the command line interface with your actual names")
        print("3. Or modify this script with your actual workspace/project names")
        
    except Exception as e:
        print(f"Error in example: {e}")
        print("Make sure your API key is correctly set in the .env file.")

if __name__ == "__main__":
    example_usage()